import { mapGetters, mapActions } from "vuex";
import Actionsheet from "vux/src/components/actionsheet/index.vue";

import template from "./settingTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  components: {
    Actionsheet,
  },
  data() {
    return {
      actFlag: false,
      actMenus: {
        menu1:
          '<span style="color:#666; font-size:12px;">确定要退出登录?</span>',
        menu2: '<span style="color:#ff3b30" click="exitLogin">确认</span>',
      },
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  methods: {
    ...mapActions(["SET_USER_INFO_DATA", "SET_ACCOUNT_DATA"]),
    actClick(key) {
      if (key == "menu2") {
        this.exitLogin();
        return;
      }
      console.log(key);
    },
    exitLogin() {
      //退出登录
      var params = {
        token: localStorage.getItem("token"),
      };
      this.$vux.loading.show();
      this.$http
        .post(this.urlRequest + "?m=api&c=user&a=logout", params)
        .then((res) => {
          this.$vux.loading.hide();
          localStorage.removeItem("token");
          this.SET_USER_INFO_DATA({
            Obj: {},
          });
          this.SET_ACCOUNT_DATA({
            Obj: {},
          });
          this.$vux.toast.show({
            text: "退出成功！",
          });
          this.$router.push({
            path: "/login",
          });
        })
        .catch((error) => {
          this.$vux.loading.hide();
          this.$vux.toast.show({
            text: "数据请求超时",
          });
        });
    },
  },
};

// WEBPACK FOOTER //
// ./src/components/personalCenter/setting/setting.vue
